function inital() {
	//alert("jih");
	$("#dialog-form").dialog({
		autoOpen : false,
		draggable : false,
		show : "slide",
		hide : "slide",
		modal : true,
		width : 500,
		resizable : false,
		position : [ "center", 50 ],
		buttons : {
			"SAVE" : function() {
				//alert("Here");
				var diagName=$("#diagName").val();
				var diagType=$("#diagType").val();
				var diaglocation=$("#diaglocation").val();
				var diagCity=$("#diagCity").val();
				var diagQuan=$("#diagQuan").val();
				var diagUnit=$("#diagUnit").val();
				var diagDate=$("#diagDate").val();
				
				sendToServerInsert(diagName,diagType,diaglocation,diagCity,diagQuan,diagUnit,diagDate);
			},
			"CANCEL" : function() {
				$(this).dialog("close");
			}
		}
	});
	
	$('#diagDate').datepicker({
		//inline : true,
		defaultDate : '0d',
		maxDate : '0d',
		minDate : '-30d',
		changeMonth : true,
		changeYear : true
	});
}

function onclick_newRS() {
	// alert("ready");
	//resetInput();
	$("#dialog-form").dialog("open");
	// new Dialog("deefe").show();
}

function sendToServerInsert(diagName,diagType,diaglocation,diagCity,diagQuan,diagUnit,diagDate){
	//alert("Here");
	var RE = {
			"diagName":diagName,
			"diagType":diagType,
			"diaglocation":diaglocation,
			"diagCity":diagCity,
			"diagQuan":diagQuan,
			"diagUnit":diagUnit,
			"diagDate":diagDate
		};

		$.ajax({
			type : "POST",
			url : "../InsertNewResource",
			data : RE,
			success : callbackRI,
			dataType : "json"
		});
}

function callbackRI(data) {
	if (data.result) {
		alert("Resource Successfully saved");
		$("#dialog-form").dialog("close");
		window.location.reload();
	} else {
		alert("Save failed");
		window.location.reload();
	}
	$("#dialog-form").dialog("close");
}

function onClick_edit(type,rs_id){
	//alert("onClick_edit");
	var num=$("#txt"+rs_id).val();
	if(type=="s"){
		num="-"+num;
	}
	//alert(rs_id);
	sendToServerUpdate(rs_id,num);
}

function sendToServerUpdate(rs_id,quantity){
	var RU = {
			"id_rs":rs_id,
			"quantity":quantity
		};

		$.ajax({
			type : "POST",
			url : "../UpdateResource",
			data : RU,
			success : callbackRU,
			dataType : "json"
		});
}

function callbackRU(data) {
	if (data.result) {
		alert("Successfully Updated!");
		window.location.reload();
	} else {
		alert("Fail to Update");
	}
}